package com.imu.purse.modules.base.dao;

import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.imu.core.base.BaseMapper;
import com.imu.purse.modules.base.entity.DictInfo;

/**
 * 数据字典
 * @author sunhongwei
 * @email sunhongwei@jshijian.com
 * @date 2017-11-03 20:34:20
 * Copyright (c) 2017 武汉极时间科技有限公司 版权所有 
 * Jshijian aloha CO.,LTD. All Rights Reserved. 
 */
public interface DictInfoMapper extends BaseMapper<DictInfo>
{
	/**
     * 分页查询
     * @param pageNo 页号
     * @param pageSize 每页显示记录数
     * @return
     */
	@Select({
		"<script>",
		    "SELECT id,",
					"gid,",
					"label,",
					"value,",
					"sort,",
					"remarks,",
					"cid,",
					"cs,",
					"mid,",
					"ms,",
					"del_flag",
		    "FROM sys_dict_info ",
		    "WHERE 1 = 1",
			"<when test = 'gid != null'>",
		    	"AND `gid` = #{gid}",
		    "</when>",
			"<when test = 'label != null'>",
		    	"AND `label` = #{label}",
		    "</when>",
			"<when test = 'value != null'>",
		    	"AND `value` = #{value}",
		    "</when>",
			"<when test = 'sort != null'>",
		    	"AND `sort` = #{sort}",
		    "</when>",
			"<when test = 'remarks != null'>",
		    	"AND `remarks` = #{remarks}",
		    "</when>",
			"<when test = 'cid != null'>",
		    	"AND `cid` = #{cid}",
		    "</when>",
			"<when test = 'mid != null'>",
		    	"AND `mid` = #{mid}",
		    "</when>",
		    "<when test = 'stime != null'>",
		    	"AND cs &gt;= #{stime}",
		    "</when>",
		    "<when test = 'etime != null'>",
				"AND cs &lt;= #{etime}",
			"</when>",
		    "ORDER BY cs DESC",
    	"</script>"
	})
    public List<DictInfo> findByPage(final DictInfo entity);
	
	/**
     * 分页查询
     * @param pageNo 页号
     * @param pageSize 每页显示记录数
     * @return
     */
	@Select({
		"<script>",
		    "SELECT i.id as id,",
					"i.gid as gid,",
					"i.label as label,",
					"i.value as value,",
					"i.sort as sort,",
					"i.remarks as remarks,",
					"i.cid as cid,",
					"i.cs as cs,",
					"i.mid as mid,",
					"i.ms as ms,",
					"i.del_flag as del_flag",
		    "FROM sys_dict d, sys_dict_info i ",
		    "WHERE d.id = i.gid",
			"<when test = 'code != null'>",
		    	"AND d.`code` = #{code}",
		    "</when>",
		    "<when test = 'ts != null'>",
		    	"AND i.`ms` &gt;= #{ts}",
		    "</when>",
		    "ORDER BY sort ASC",
    	"</script>"
	})
    public List<DictInfo> findByCode(@Param("code") String code, @Param("ts") Long ts);	
}
